$(function(){
    var layer = layui.layer
    // console.log($('#exit'));
    $('#exit').click(function(){
        console.log('ok');
        layer.confirm('确认要退出吗?', {icon: 3, title:'提示'}, function(index){
           location.href = 'login.html'
            layer.close(index);
          });
    })

    userinfo()
    // 更换头像
    function userinfo() {
        $.get('/my/userinfo',function(res) {
            console.log(res);
            if(res.status != 0) {
                return layer.msg(res.message)
            }
            layer.msg(res.message)
            renderAvater(res.data)
        })
    }

    function  renderAvater(data) {
       var name = data.nickname || data.username
       $('.weclom').html('欢迎&nbsp;&nbsp;' +name)
       if (data.user_pic != null) {
           $('.layui-nav-img').css('src',data.user_pic).show()
           $('.scriptPot').hide()
       }else {
        //    渲染文字头像
        $('.layui-nav-img').hide()
        $('.scriptPot').html(name[0].toUpperCase()).show()
       }
    }
})